https://cran.r-project.org/web/packages/rtweet/vignettes/intro.html

# twitter library 
library(rtweet)

# plotting and pipes - tidyverse
library(ggplot2)
library(dplyr, warn.conflicts = FALSE)
options(dplyr.summarise.inform = FALSE) # Suppress summarise info

# text mining library
suppressPackageStartupMessages(library(tidyverse)) # suppress startup message

# date/time libaray
library(lubridate, warn.conflicts = FALSE)
get_token()
## <Token>
## <oauth_endpoint>
##  request:   https://api.twitter.com/oauth/request_token
##  authorize: https://api.twitter.com/oauth/authenticate
##  access:    https://api.twitter.com/oauth/access_token
## <oauth_app> Data104
##   key:    lfrCxMQkaeS6eg88o7Dnx96Uj
##   secret: <hidden>
## <credentials> oauth_token, oauth_token_secret, user_id, screen_name
## ---

Retrieve most recent 3200 timelines of Trump and Biden

tmls <- get_timelines(c("JoeBiden", "realDonaldTrump"), n = 3200, check = FALSE)
write_as_csv(tmls, "test.csv")
timelinesdf <- read_twitter_csv("test.csv")
table(timelinesdf$screen_name)
## 
##        JoeBiden realDonaldTrump 
##            3200            3187

Download Data from a Hastag

rt <- search_tweets(
  "Autodesk", n = 18000, include_rts = FALSE
)

## preview tweets data
rt
## preview users data
users_data(rt)
## plot time series (if ggplot2 is installed)
ts_plot(rt)

write_as_csv(rt, "twitter.csv")
df <- read_twitter_csv("twitter.csv")
df
## plot time series of tweets
ts_plot(rt, "1 hours") +
  ggplot2::theme_minimal() +
  ggplot2::theme(plot.title = ggplot2::element_text(face = "bold")) +
  ggplot2::labs(
    x = NULL, y = NULL,
    title = "Frequency of #rstats Twitter statuses from past 9 days",
    subtitle = "Twitter status (tweet) counts aggregated using three-hour intervals",
    caption = "\nSource: Data collected from Twitter's REST API via rtweet"
  )